package com.frank.towerrush.activity;

import com.frank.towerrush.R;
import com.frank.towerrush.util.SystemParameter;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

public class SettingActivity extends BaseActivity implements OnClickListener, OnSeekBarChangeListener {
    Button btnSoundOn;
    SeekBar barMusic;
    SeekBar barSound;

    @Override
    protected void init() {
        setContentView(R.layout.activity_setting);
        // 获得控件
        btnSoundOn = (Button) findViewById(R.id.setting_btn_sound_switch);
        barMusic = (SeekBar) findViewById(R.id.setting_bar_music);
        barSound = (SeekBar) findViewById(R.id.setting_bar_sound);
    }

    @Override
    protected void event() {
        // 添加监听
        btnSoundOn.setOnClickListener(this);
        barMusic.setOnSeekBarChangeListener(this);
        barSound.setOnSeekBarChangeListener(this);
    }

    @Override
    protected void loadData() {
        // 设置状态
        btnSoundOn.setBackgroundResource(SystemParameter.soundOn ? R.drawable.audio_on : R.drawable.audio_off);
        barMusic.setProgress(SystemParameter.musicVolume);
        barSound.setProgress(SystemParameter.soundVolume);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        switch (seekBar.getId()) {
        case R.id.setting_bar_music:
            SystemParameter.musicVolume = progress;
            SystemParameter.soundService.changeVolume();
            break;
        case R.id.setting_bar_sound:
            SystemParameter.soundVolume = progress;
            // TODO 调整音量
            break;
        default:
            break;
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // Do nothing now
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // Do nothing now
    }

    @Override
    public void onClick(View v) {
        SystemParameter.soundOn = !SystemParameter.soundOn;
        btnSoundOn.setBackgroundResource(SystemParameter.soundOn ? R.drawable.audio_on : R.drawable.audio_off);
        if (SystemParameter.soundOn) {
            SystemParameter.soundService.musicStart(this, SystemParameter.SystemAudio.MUSIC_PLAY, true);
        } else {
            SystemParameter.soundService.musicStop();
        }
        // TODO 音乐切换
    }

}
